package com.nowc.week.w107_ak;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

public class f {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solve();
        out.flush();
        out.close();
        br.close();
    }

    static class Node {
        int val;
        int x;
        int y;
        Node(int val, int x, int y) {
            this.val = val;
            this.x = x;
            this.y = y;
        }
    }

    static int[] dx = {-1, 0, 1, 0, -1, -1, 1, 1}, dy = {0, 1, 0, -1, -1, 1, 1, -1};

    static void solve() throws IOException {
        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);
        int q = Integer.parseInt(in[2]);
        int[][] a = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            in = br.readLine().split(" ");
            for (int j = 1; j <= m; j++) {
                a[i][j] = Integer.parseInt(in[j - 1]);
            }
        }
        int[][] b = new int[q + 1][2];
        for (int i = 1; i <= q; i++) {
            in = br.readLine().split(" ");
            b[i][0] = Integer.parseInt(in[0]);
            b[i][1] = i;
        }
        Arrays.sort(b, Comparator.comparingInt(x -> x[0]));
        PriorityQueue<Node> pq = new PriorityQueue<>(new Comparator<Node>() {
            @Override
            public int compare(Node o1, Node o2) {
                return o1.val - o2.val;
            }
        });

        for (int j = 1; j <= m; j++) {
            pq.add(new Node(a[1][j], 1, j));
        }
        int sum = 0;
        int[] ans = new int[q + 1];
        int[][] vis = new int[n + 1][m + 1];
        for (int i = 1; i <= q; i++) {
            int[] o = b[i];
            while (!pq.isEmpty() && pq.peek().val <= o[0]) {
                int x = pq.peek().x, y = pq.peek().y;
                pq.poll();
                if (vis[x][y] != 0) continue;
                vis[x][y] = 1;
                sum++;
                for (int k = 0; k < 4; k++) {
                    int nx = x + dx[k], ny = y + dy[k];
                    if (nx < 1 || nx > n || ny < 1 || ny > m || vis[nx][ny] == 1) continue;
                    pq.add(new Node(a[nx][ny], nx, ny));
                }
            }
            ans[o[1]] = sum;
        }

        for (int i = 1; i <= q; i++) {
            out.println(ans[i]);
        }

    }

}
